﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Newtonsoft.Json;

namespace Domain.Model.ValueObject
{
    /// <summary>
    /// 菜单类
    /// <remarks>作者：何智杰，日期：2013/05/15</remarks>
    /// </summary>
    [Serializable]
    public class EasyUiMenu
    {
        /// <summary>
        /// 菜单id
        /// </summary>
        public string menuid { get; set; }
        /// <summary>
        /// 菜单名称
        /// </summary>
        public string menuname { get; set; }
        /// <summary>
        /// 菜单链接
        /// </summary>
        public string url { get; set; }
        /// <summary>
        /// 菜单图标
        /// </summary>
        public string icon { get; set; }
        /// <summary>
        /// 子菜单
        /// </summary>
        public List<EasyUiMenu> menus { get; set; }

        /// <summary>
        /// 所属性模块ID
        /// </summary>
        [JsonIgnore]
        public Guid belongMoudle { get; set; }

        /// <summary>
        /// 菜单类
        /// </summary>
        public EasyUiMenu()
        {
            this.menus = new List<EasyUiMenu>();
        }

        /// <summary>
        /// 转换为Json字符串
        /// </summary>
        /// <returns></returns>
        public string ToJson()
        {
            JsonSerializerSettings setting = new JsonSerializerSettings()
            {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
                NullValueHandling = NullValueHandling.Ignore
            };

            var scriptSerializer = JsonSerializer.Create(setting);
            using (var sw = new StringWriter())
            {
                scriptSerializer.Serialize(sw, this);
                string json = sw.ToString();
                return json;
            }
        }
    }
}
